package references

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 获取数组长度
type ArrayLength struct {
	base.NoOperandsInstruction
}

func (self *ArrayLength) Execute(frame *runtime_area.Frame) {
	stack := frame.OperandStack()
	// 从操作数栈中弹出数组对象
	arrayObject := stack.PopRef()
	if arrayObject == nil {
		panic("java.lang.NullPointerException")
	}
	// 获取数组长度并压栈
	arrayLength := arrayObject.ArrayLength()
	stack.PushInt(arrayLength)
}